<template>
	<view class="">
		<view class="pl-20 pr-20 pb-20 bg-white">
			<u-search placeholder="搜索" v-model="searchData.name" shape="square" :showAction="false" @search="onSearch" />
		</view>
		<view class="my-list">
			<u-list :height="swiperHeight" @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in dataList" :key="index">
					<view class="item flex" @click="$u.route('pages/shop/default/margin-detail', {id: item.id})">
						<image class="width-160 height-160 border-radius-10" :src="item.logoImage"></image>
						<view class="ml-20 flex column justify-between">
							<text class="fweigh-600">{{item.storeName}}</text>
							<view class="line-gray fsize-28 ml-20">
								<view>
									<text>保证金:￥</text>
									<text class="line-red">{{item.earnestBalance}}</text>
								</view>
								<view>
									<text>{{item.address}}</text>
								</view>
							</view>
						</view>
					</view>
				</u-list-item>
				<u-loadmore 
					:status="loadmore.status" 
					:icon-type="loadmore.iconType" 
					:load-text="loadmore.loadText.loadText" 
					margin-top="40"
					margin-bottom="20" 
					class="coreshop-padding-top-10" 
				/>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
				dataList: [],
				searchData: {
					name:'',
					page: 1,
					limit: 10,
				}
			}
		},
		onLoad() {
			this.getPageList()
			uni.$on('upMarginList', ()=>{
				this.onSearch()
			})
		},
		onUnload() {
			uni.$off('upMarginList')
		},
		methods: {
			onSearch(){
				this.dataList = []
				this.searchData.page = 1
				this.getPageList()
			},
			getPageList() {
				this.$reqPost('GetFinanceStoreList', this.searchData).then(res => {
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fontWeightNormal{ font-weight: normal;}
	.paddingTop20{ padding-top: 20rpx;}
</style>
